package com.letoken.platform.repo.mall.dao;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.letoken.platform.repo.app.res.config.AmbHistoryRes;
import com.letoken.platform.repo.app.res.config.QueryLetokenHistoryRes;
import com.letoken.platform.repo.dao.SpiceBaseMapper;
import com.letoken.platform.repo.mall.po.AppMallAmbassadorHistory;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.letoken.platform.repo.mall.po.AppMallAmbassadorRecord;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * <p>
 * 分红与流通，为了前端查询 Mapper 接口
 * </p>
 *
 * @author author
 * @since 2023-06-12
 */
public interface AppMallAmbassadorHistoryMapper extends SpiceBaseMapper<AppMallAmbassadorHistory> {


    @Select("select * from app_mall_ambassador_history where user_id = #{userId} and create_time >= #{startTime} and create_time < #{endTime} order by create_time desc ")
    Page<AmbHistoryRes> ambRecords(@Param("page") Page<AmbHistoryRes> page, @Param("userId") Integer userId, @Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime);


    @Select("select IFNULL(sum(amount),0) from app_mall_ambassador_history where user_id = #{userId} and create_time >= #{startTime} and create_time < #{endTime} ")
    BigDecimal ambRecordData( @Param("userId") Integer userId, @Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime);

}
